﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using emp.Utility;
using System.Collections;
using emp.Model.SysManage;
using System.Data;
using System.Data.SqlClient;
using emp.SqlServerDAL;

public partial class crm_salienceMember_SalienceMemberList : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {   
        if (!IsPostBack)
        {
            XS();

        }
    }




    private DataTable getTableInfo(string sql)
    {
        DataSet data = new DataSet();
        using (SqlDataAdapter sda = new SqlDataAdapter())
        {
            try
            {
                sda.SelectCommand = new SqlCommand();
                sda.SelectCommand.CommandText = sql;
                sda.SelectCommand.Connection = new SqlConnection(SQLHelper.CONN_STRING_NON_DTC);
                sda.Fill(data);
            }
            catch { }
        }
        return data.Tables[0];
    }
    protected void selectBtn_Click(object sender, EventArgs e)
    {

        XS();



    }

    private void XS() 
    {
        string sqls = "";
        if (BEGN.Text != null && BEGN.Text != "")
        {
            sqls += " and  [TCI_DATE]>='" + BEGN.Text + " 00:00:00'";
        }
        if (END.Text != null && END.Text!= "")
        {
            sqls += " and  [TCI_DATE]<='" + END.Text + " 23:59:59'";
        }


        string sql = "select  count(*)  from TASTE_CAR_INFORMATION  where 1=1" + sqls;
        DataTable dt = getTableInfo(sql);
        if (dt.Rows.Count == 0)
        {
            Label1.Text = "0";
            Label2.Text = "0";
        }
        else 
        {
            Label1.Text = dt.Rows[0][0].ToString();
            Label2.Text = dt.Rows[0][0].ToString();
        }
        //品味车苑
        string brand_cac_uid = System.Configuration.ConfigurationSettings.AppSettings["brand_cac_uid"];


        sql = "select   count(*) from [INDIVIDUAL_DEALERS] where   [ILD_ASSIGN_FLAG]>0 and [ILD_IND_URN] in(select    [IND_URN] from [INDIVIDUALS] where [IND_CELLPHONE_1] in (SELECT [TCI_TELEPHONE] from [TASTE_CAR_INFORMATION]  where 1=1  " + sqls + " ) ) and [ILD_CAC_UID]='" + brand_cac_uid + "'";
        dt = getTableInfo(sql);
        if (dt.Rows.Count == 0)
        {
            Label4.Text = "0";
        }
        else
        {
            Label4.Text = dt.Rows[0][0].ToString();
        }



        sql = "select  count(*) from INDIVIDUAL_DEALERS where ILD_IS_BUY='Y' and [ILD_IND_URN] in(select    [IND_URN] from [INDIVIDUALS] where [IND_CELLPHONE_1] in (SELECT [TCI_TELEPHONE] from [TASTE_CAR_INFORMATION]  where 1=1  " + sqls + " ) ) and [ILD_CAC_UID]='" + brand_cac_uid + "'";
        dt = getTableInfo(sql);
        if (dt.Rows.Count == 0)
        {
            Label6.Text = "0";
        }
        else
        {
            Label6.Text = dt.Rows[0][0].ToString();
        }
        Label6.Text = dt.Rows[0][0].ToString();


        Label3.Text = "100.00%";
        if (Label4.Text == "0")
        {
            Label5.Text = "0.00%";
        }
        else 
        { 
            Label5.Text = (float.Parse(Label4.Text) / float.Parse(Label1.Text)).ToString("P");
        }


        if (Label6.Text == "0")
        {
            Label7.Text = "0.00%";
        }
        else
        {
            Label7.Text = (float.Parse(Label6.Text) / float.Parse(Label1.Text)).ToString("P");
        }



        if (Label1.Text=="0")
        {
            Label3.Text = "-";
            Label5.Text = "-";
            Label7.Text = "-";
        }

        
    }
}
